﻿using DTOs;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.Domain;
using RBAC.Domain.Service.Impl;
using RBAC.Domain.Service.Interfae;
using RBACDuYaJun.Api.Appliction.Command.UserRoleCommand;
using RBACDuYaJun.Api.Dtos;

namespace RBACDuYaJun.Api.Controllers
{
    /// <summary>
    /// 用户与角色的关系管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    //[Authorize]//（JWT）
    [ApiController]
    public class UserRoleController : ControllerBase
    {
        private readonly IMediator _mediator;
        ///// <summary>
        ///// 用户服务层
        ///// </summary>
        //protected readonly UserServices _userServices;
        ///// <summary>
        ///// 角色服务
        ///// </summary>
        //protected readonly RoleService _roleService;
        /// <summary>
        /// 用户与角色服务
        /// </summary>
        protected readonly IUserRoleService _userRoleService;
        public UserRoleController(IMediator mediator,IUserRoleService userRoleService)
        {
           _mediator = mediator;
            _userRoleService = userRoleService;
        }


        ///// <summary>
        ///// 添加角色与员工的关系（利用IMediator）
        ///// </summary>
        ///// <param name="userRole"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<int> AddUserRoles(UserRoleCreateCommand command)
        //{
        //    return await _mediator.Send(command);
        //}

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="rid"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddUserRoles(int rid, List<int> uid)
        {

         return await _userRoleService.AddUserRoles(rid, uid);

        }
        /// <summary>
        /// 删除角色与员工的关系（利用IMediator）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteUserRoles([FromQuery]UserRoleDeleteCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 显示角色与员工的关系（利用IMediator）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<UserRoleDto>> GetUserRole([FromQuery]UserRoleShowCommand command)
        {

            return await _mediator.Send(command);
        }
        /// <summary>
        /// 反填员工（利用IMediator）
        /// </summary>
        /// <param name="Ridd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<UserRoleDto>> GetUserRoleList([FromQuery] UserRoleGetIdCommand command)
        {
            return await _mediator.Send(command);
            //return await _userRoleService.GetUserRoleList(Ridd);
        }
       
    }
}
